package com.buaa.dto.impl;

import com.buaa.dto.UserExtensionDTO;
import com.buaa.entity.UserExtension;

import java.time.LocalDateTime;

public class UserExtensionDTOConvImp {
    public UserExtension toEntity(UserExtensionDTO userExtensionDTO) {
        if(userExtensionDTO == null) {
            return null;
        }
        UserExtension userExtension = new UserExtension();
        LocalDateTime date = LocalDateTime.now();
        if (null == userExtensionDTO.getId()){  // 说明是第一次创建 userext， insert
            userExtension.setCreateTime(date);
            userExtension.setRevisionTime(date);
            userExtension.setCreateBy("郑凯文"); // TBD 待更新
            userExtension.setReviser("冯浩宇");
        }else {//说明是更新，设置更新人员，更新日期
            userExtension.setRevisionTime(date);
            userExtension.setReviser("冯浩宇");
        }
        userExtension.setId(userExtensionDTO.getId());
        userExtension.setUserId(userExtensionDTO.getUserId());
        userExtension.setGender(userExtensionDTO.getGender());
        userExtension.setDateOfBirth(userExtensionDTO.getDateOfBirth());
        userExtension.setJoinDate(userExtensionDTO.getJoinDate());
        userExtension.setPoliceRank( userExtensionDTO.getPoliceRank());
        userExtension.setDepartment(userExtensionDTO.getDepartment());
        userExtension.setDutyStation(userExtensionDTO.getDutyStation());
        userExtension.setPhoneNumber(userExtensionDTO.getPhoneNumber());
        userExtension.setHomeAddress(userExtensionDTO.getHomeAddress());
        userExtension.setEmail(userExtensionDTO.getEmail());
        userExtension.setEmergencyContactName(userExtensionDTO.getEmergencyContactName());
        userExtension.setEmergencyContactPhone(userExtensionDTO.getEmergencyContactPhone());
        userExtension.setPoliceProvince(userExtensionDTO.getPoliceProvince());
        userExtension.setPoliceCity(userExtensionDTO.getPoliceCity());
        userExtension.setIsActive(userExtensionDTO.getIsActive());
        userExtension.setPoliceOrg(userExtensionDTO.getPoliceOrg());
        userExtension.setStationId(userExtensionDTO.getStationId());
        return userExtension;
    }

}
